# 带着二哈去旅行丶:ZZQ
# 生成时间：2021/12/6 下午9:44

print("检查错误")
"""
import csv

filename = 'data/death_valley_2018_simple.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    for index, column_header in enumerate(header_row):
        print(index, column_header)
"""
import csv
import matplotlib.pyplot as plt
from datetime import datetime

filename = 'data/death_valley_2018_simple.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    # 从文件中获取日期、最高温度和最低温度
    dates, highs, lows = [], [], []
    for row in reader:
        current_date = datetime.strptime(row[2], '%Y-%m-%d')
    # 修改错误
        try:
            high = int(row[4])
        # 这里将最高温度删除了 报错 ValueError: invalid literal for int() with base 10: ''
            low = int(row[5])
        except ValueError:
            print(f"Missing data for {current_date}")
        else:
            dates.append(current_date)
            highs.append(high)
            lows.append(low)

# 根据最高温度和最低温度绘制图形
plt.style.use('Solarize_Light2')
fig, ax = plt.subplots(figsize=(10, 6), dpi=128)  # 指定图表分辨率
ax.plot(dates, highs, c='red')
ax.plot(dates, lows, c='blue')
ax.fill_between(dates, highs, lows, facecolor='blue', alpha=0.1)
# 设置图形格式
title = "2018年每日最高温度和最低温度\n美国加利福利亚州死亡谷"
ax.set_title(title, fontsize=20)
ax.set_xlabel('', fontsize=16)                          # 设置x轴
fig.autofmt_xdate()                                     # 调用fig.autofmt_xdate()函数绘制倾斜的日期标签，避免重叠
ax.set_ylabel('温度（F）', fontsize=16)                 # 设置y轴
ax.tick_params(axis='both', which='major', labelsize=16)    # 设置刻度的样式 both影响x和y labelsize刻度标记字号
plt.show()
